package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.SmsHomeRecommendProductApi;
import com.mail.model.db.SmsHomeRecommendProduct;
import com.mail.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsHomeRecommendProductService {

    @DubboReference
    private SmsHomeRecommendProductApi smsHomeRecommendProductApi;

    public void addRecommendProduct(List<SmsHomeRecommendProduct> recommendProductsList) {
        for (SmsHomeRecommendProduct smsHomeRecommendProduct : recommendProductsList) {
            smsHomeRecommendProductApi.save(smsHomeRecommendProduct);
        }
    }

    public void deleteRecommendProduct(List<Long> ids) {
        smsHomeRecommendProductApi.deleteRecommendProduct(ids);
    }

    public PageResult getRecommendProductByPage(Long pageNum, Long pageSize, String productName, Integer recommendStatus) {
        Page<SmsHomeRecommendProduct> page = smsHomeRecommendProductApi.getRecommendProductByPage(pageNum,pageSize,productName,recommendStatus);
        return new PageResult(Long.parseLong(String.valueOf(page.getCurrent())), Long.parseLong(String.valueOf(page.getSize())), Long.parseLong(String.valueOf(page.getTotal())), page.getRecords());    }

    public void updateRecommendProduct(List<Long> ids, Integer recommendStatus) {
        for (Long id : ids) {
            smsHomeRecommendProductApi.updateRecommendProduct(id,recommendStatus);
        }
    }

    public void updateSortRecommendProduct(Long id, Integer sort) {
        smsHomeRecommendProductApi.updateSortRecommendProduct(id,sort);
    }
}
